<!--_meta 作为公共模版分离出去-->
<include file='public/_meta'>
<!--/meta 作为公共模版分离出去-->

<title>编辑</title>
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<body>
<article class="page-container">
	<form action="{:url('edit')}" method="post" class="form form-horizontal" id="form-member-add" enctype="multipart/form-data">
		<input type="hidden" name="id" value="{$data.id}">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>车牌号：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$data.car_id.car_sn}" placeholder="无车牌则用车架号后6位..." id="search_text" name="car_sn">
			</div>
		</div>
		<div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">
                        <span class="c-red">*</span>
                        保险类型：</label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <span class="select-box" style="width:300px;">
                            <select class="select" name="secure_type" size="1">
                                <option value="1" {$data['secure_type']==1?'selected':''}>交强险</option>
                                <option value="2" {$data['secure_type']==2?'selected':''}>商业保险</option>

                                <option value="3" {$data['secure_type']==3?'selected':''}>承运人责任险</option>
                            </select>
                        </span>
                    </div>
        </div>
        <div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>保险公司：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<span class="select-box" style="width:300px;">
                    <select class="select" name="secure_company" size="1">
                        <option value="1" {$data['secure_company']==1?'selected':''}>平安保险</option>
                        <option value="2" {$data['secure_company']==2?'selected':''}>阳光保险</option>
                        <option value="3" {$data['secure_company']==3?'selected':''}>中银保险</option>
                        <option value="4" {$data['secure_company']==4?'selected':''}>中保保险</option>
                        <option value="5" {$data['secure_company']==5?'selected':''}>中华联合保险</option>
                        <option value="6" {$data['secure_company']==6?'selected':''}>太平洋保险</option>
                        <option value="7" {$data['secure_company']==7?'selected':''}>都邦财产保险</option>
                    </select>
                </span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>保险时间：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
				<input type="text" class="input-text Wdate" value="{$data.secure_start}" style="width: 150px;" onfocus="WdatePicker()" placeholder="" id="secure_start" name="secure_start"> 起 <input type="text" class="input-text Wdate" value="{$data.secure_end}" style="width: 150px;" onfocus="WdatePicker()" placeholder="" id="secure_end" name="secure_end"> 止
			</div>
		</div>		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">保险保费：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$data.secure_money}" placeholder=""  name="secure_money">
			</div>
		</div>
		<foreach $data['secureFile'] as $value>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">原有附件：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
				<ul>
					<li><a href="__UPLOADS__/{$value.file_url}" target="_blank"><i class="icon Hui-iconfont f-30">&#xe613;</i></a><a href="javascript:void(0);" onclick="product_del(this,{$value['id']})" class="ml-10">删除</a></li>
					
				</ul>
			</div>
		</div>
		</foreach>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">附件：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
				<span class="btn-upload form-group">
				<input class="input-text upload-url" type="text"  readonly nullmsg="请添加附件！" style="width:200px">
				<a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
				<input type="file" multiple name="uploadfile[]" class="input-file">
				</span> 
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">备注：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
				<textarea class="textarea" name="secure_desc">{$data.secure_desc}</textarea>

			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去-->
<include file='public/_footer'>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/autocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-member-add").validate({
		rules:{
			car_unique_id:{
				required:true,
				minlength:17,
				maxlength:17
			},
			secure_company:{
				required:true,
			},
			secure_id:{
				required:true,
			},
			secure_start:{
				required:true,
			},
			secure_end:{
				required:true,
			},
			
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				 success: function(data) { 
				 	var index = parent.layer.getFrameIndex(window.name);
					//parent.$('.btn-refresh').click();
                if(data['status']==0){
                
                	layer.msg(data['msg'], {icon:6,time:1000},function(){

						parent.location.href = '{:url('index')}';              		
						parent.layer.close(index);
                	});

                }else{
                	layer.msg(data['msg']);

                }
            }


			});

		}
	});
});

$(".textarea").Huitextarealength({
	maxlength:100,
	exceed:false,
});

$(function(){
	var url = "{:url('index/Record/ajaxGetCarSn')}";
	// var searchURL = "/cases/search.action";
	var isClicked = false;
	var defauntkeyword = "请输入关键词";
	$("#search_text").autocomplete(url, {
		scroll:false,
		selectFirst:false,
		delay:5,
		max:10,
		dataType:"json",//ajax的跨域，必须用jsonp,jQuery自动会加一个callback参数,后台要获得callback参数，并写回来
			//自定义提示
		tips:function(data) {
				//这里的data是跟formatItem 的data是一样的，所以格式也一样
			return data.pinyin;
		},
		parse: function(data) {
			if(data==null||typeof(data)=="undefined"||data.length==0){
				return null;
			}
			// console.log(data);

			// data = data.keylist;
			var rows = [];
			for(var i=0; i<data.length; i++){
				rows[rows.length] = {
					data:data[i],//这里data是对象数组，格式[{key:aa,address:nn},{key:aa,address:nn}]
					value:data[i].car_sn,
					result:data[i].car_sn
				};
			}
			return rows;
		},
		extraParams: {query:function (){return $('#search_text').val();}},
		formatItem: function(data, i, total) {  //就是下拉框显示的内容，可以有格式之类的
			return "<p class=''>"+data.car_sn+"</p>";
		},
		formatMatch: function(data, i, total) {  //要匹配的内容
			return data.car_sn;
		},
		formatResult: function(data) {  //最终在inputText里显示的内容，就是以后要搜索的内容
			return data.car_sn;
		}
	}).result(function(e, data) {
		if(!isClicked) {
			// startSearch();
		}
	});

});


/*文件-删除*/
function product_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url('del_file')}',
			data:{'id':id},
			dataType: 'json',
			success: function(data){
				if(data.code == 1){
					$(obj).parents("li").remove();
					layer.msg('已删除!',{icon:1,time:1000});
				}else{
					layer.msg('删除失败,请稍后再试');
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>